package com.jhhc.StormSurgeForecast.StormSurge.ServiceImpl;

import com.jhhc.StormSurgeForecast.AstronomicalTide.Dao.BDMS_FBC_RESULT_SMapper;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.FBC.BDMS_FBC_RESULT_S;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.ZJBO.SeaWall;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.ZJBO.SeaWallData;
import com.jhhc.StormSurgeForecast.StormSurge.Service.BDMS_FBC_RESULT_SService;
import com.jhhc.StormSurgeForecast.StormSurge.Uitl.BinaryUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * (BDMS_FBC_RESULT_SMapper)表服务实现类
 *
 * @author makejava
 * @since 2022-10-26 11:50:34
 */
@Service("BDMS_FBC_RESULT_SService")
public class BDMS_FBC_RESULT_SServiceImpl implements BDMS_FBC_RESULT_SService {
    @Resource
    private BDMS_FBC_RESULT_SMapper bdms_fbc_result_sMapper;

    @Override
    public List<SeaWall> selectAll(String CSCHEMEID, String SWID) {
        BinaryUtil binaryUtil = new BinaryUtil();
        List<SeaWall> seaWalls = new ArrayList<>();
        if (SWID == null) {
            List<BDMS_FBC_RESULT_S> bdms_fbc_result_sList = bdms_fbc_result_sMapper.GetCalResultsByBanks(CSCHEMEID);
            if (bdms_fbc_result_sList.size() > 0) {
                List<String> strings = new ArrayList<>();
                for (BDMS_FBC_RESULT_S bdms_fbc_result_s : bdms_fbc_result_sList) {
                    if (!strings.contains(String.valueOf(bdms_fbc_result_s.getSwid()))) {
                        strings.add(String.valueOf(bdms_fbc_result_s.getSwid()));
                    }
                }
                for (int i = 0; i < strings.size(); i++) {
                    SeaWall seaWall = new SeaWall();
                    seaWall.setSwid(i + 1);
                    List<BDMS_FBC_RESULT_S> bdms_fbc_result_ss = bdms_fbc_result_sList
                            .stream().filter(BDMS_FBC_RESULT_S -> BDMS_FBC_RESULT_S.getSwid() == seaWall.getSwid()).collect(Collectors.toList());
                    List<SeaWallData> seaWallData = binaryUtil.ZJclassification(bdms_fbc_result_ss);
                    seaWall.setSeaWallDatas(seaWallData);
                    seaWalls.add(seaWall);
                }
            }
            return seaWalls;
        }else {
            List<BDMS_FBC_RESULT_S> bdms_fbc_result_sList = bdms_fbc_result_sMapper.GetCalResultsByBank(CSCHEMEID, SWID);
            if (bdms_fbc_result_sList.size() > 0) {
                SeaWall seaWall = new SeaWall();
                seaWall.setSwid(bdms_fbc_result_sList.get(0).getSwid());
                List<SeaWallData> seaWallData = binaryUtil.ZJclassification(bdms_fbc_result_sList);
                seaWall.setSeaWallDatas(seaWallData);
                seaWalls.add(seaWall);
            }
            return seaWalls;
        }
    }
}
